home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / share / pyshared / ibus / text.py < prev    next >
Encoding:
Python Source  |  2009-11-05  |  1.9 KB  |  68 lines

  1. # vim:set et sts=4 sw=4:
  2. #
  3. # ibus - The Input Bus
  4. #
  5. # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Lesser General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. # GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with this program; if not, write to the
  19. # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20. # Boston, MA  02111-1307  USA
  21.  
  22. __all__ = (
  23.         "Text",
  24.     )
  25.  
  26. import dbus
  27. from exception import IBusException
  28. from serializable import *
  29. from attribute import AttrList
  30.  
  31. class Text(Serializable):
  32.     __gtype_name__ = "PYIBusText"
  33.     __NAME__ = "IBusText"
  34.     def __init__ (self, text="", attrs=None):
  35.         super(Text, self).__init__()
  36.         self.__text = text
  37.         self.__attrs = attrs
  38.  
  39.     def get_text(self):
  40.         return self.__text
  41.  
  42.     def get_attributes(self):
  43.         return self.__attrs
  44.  
  45.     text        = property(get_text)
  46.     attributes  = property(get_attributes)
  47.  
  48.     def serialize(self, struct):
  49.         super(Text, self).serialize(struct)
  50.         struct.append (dbus.String(self.__text))
  51.         if self.__attrs == None:
  52.             self.__attrs = AttrList()
  53.         struct.append (serialize_object(self.__attrs))
  54.  
  55.     def deserialize(self, struct):
  56.         super(Text, self).deserialize(struct)
  57.  
  58.         self.__text = struct.pop(0)
  59.         self.__attrs = deserialize_object(struct.pop(0))
  60.  
  61. def test():
  62.     text = Text("Hello")
  63.     value = serialize_object(text)
  64.     text = deserialize_object(value)
  65.  
  66. if __name__ == "__main__":
  67.     test()
  68.